<template>
  <div class="trustrank" :loading="loading">
    <div class="trustrank-title">信任度信息</div>
    <el-form label-width="150px" ref="elForm" :model="dataForm" :rules="rules">
      <el-form-item label="导入信任度设置" prop="value">
        <el-input-number
          v-model="dataForm.value"
          :step="0.1"
          :max="1000000000"
          :min="0"
        />
      </el-form-item>
      <el-row>
        <el-form-item>
          <el-button type="primary" @click="dataFormSubmit" :loading="btnLoading">
            保存
          </el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { settingGetInfo, putSetting } from "@/api/system/ai";
export default {
  data() {
    return {
      loading: false,
      btnLoading: false,
      dataForm: {
        value: 0,
      },
      // 表单校验
      rules: {
        value: [{ required: true, message: "请输入信任度", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      settingGetInfo("AI_TRUST_LEVEL")
        .then((res) => {
          this.dataForm = res.data;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          putSetting(this.dataForm)
            .then((res) => {
              this.$modal.msgSuccess(res.msg);
              this.getList();
            })
            .finally(() => {
              this.btnLoading = false;
            });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.trustrank {
  width: 97%;
  margin: 20px 0 10px;
  .trustrank-title {
    font-weight: 700;
    margin-left: 10px;
    margin-bottom: 20px;
    font-size: 16px;
    vertical-align: bottom;
    &::before {
      content: "";
      display: inline-block;
      vertical-align: bottom;
      width: 5px;
      height: 20px;
      background: #409eff;
      margin-right: 10px;
    }
  }
}
</style>
